import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/image_extended.dart';

class DengPage extends StatefulWidget {
  const DengPage({super.key});

  @override
  DengPageState createState() => DengPageState();
}

class DengPageState extends State<DengPage>
    with SingleTickerProviderStateMixin {
  double angle1 = 0;
  double angle2 = pi * 0.1;
  Timer? _timer;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: MarginPaddingUtil.all(5),
      child: Stack(
        children: [
          Transform.rotate(
            angle: angle1,
            child: ImageCommon(
              '/image/ic_deng1',
              width: 579.width,
              height: 581.width,
            ),
          ),
          Transform.rotate(
            angle: angle2,
            child: ImageCommon(
              '/image/ic_deng2',
              size: 583.width,
            ),
          ),
        ],
      ),
    );
  }

  int mill = 0;

  void start() {
    mill = DateTime.now().millisecondsSinceEpoch;
    _timer = Timer.periodic(Duration(milliseconds: 300), (timer) {
      final temp = DateTime.now().millisecondsSinceEpoch - mill;
      if (temp > 3000) {
        stop();
        return;
      }
      angle1 += pi * Random().nextDouble();
      angle2 += pi * Random().nextDouble();
      setState(() {});
    });
  }

  void stop() {
    angle1 = 0;
    angle2 = pi * 0.1;
    _timer?.cancel();
    _timer = null;
  }
}
